// Copyright (C) 2002-2008 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#ifndef __C_FPS_PARTICLE_SYSTEM_SCENE_NODE_H_INCLUDED__
#define __C_FPS_PARTICLE_SYSTEM_SCENE_NODE_H_INCLUDED__
#include "IFpsParticleSystemSceneNode.h"
#include "SFpsParticle.h"
#include "IPLWrappingFunctions.h"
#include "IFpsParticleEmitter.h"
#include "IFpsParticleAffector.h"

#define MAX_EMITTERS_OGLES1				(32)
#define MAX_EMITTERS_OGLES2				(128)
#define PARTICLES_ON_EMITTER_OGLES1		(32)
#define PARTICLES_ON_EMITTER_OGLES2		(1024)

class CFpsParticleSystemSceneNode;


typedef struct
{
	SFpsParticle* Particles;
	//SMeshBuffer* Buffer;
	tIPLGeometry* Buffer;
	int used;

	CFpsParticleSystemSceneNode* parent;
}
EmitterDesc;

#define NB_EMIT_EACH_STEP 32

//! A particle system scene node.
/** A scene node controlling a particle system. The behavior of the particles
can be controlled by setting the right particle emitters and affectors.
*/
class CFpsParticleSystemSceneNode  : public IFpsParticleSystemSceneNode
{
public:
	CFpsParticleSystemSceneNode();

	virtual void doParticleSystem(float time);
	virtual void render();

	virtual void deserializeAttributes(IAttributes* in);
	virtual IFpsParticleSystemSceneNode* clone();
	virtual void setEmitter(IFpsParticleEmitter* emitter);
	virtual void addAffector(IFpsParticleAffector* affector);
	virtual void StopEmitting();
	virtual void Restart();
	virtual bool IsActive();
	virtual bool IsEnded();

	virtual void Link();
	virtual void FreeLink();

	static void InitPool( bool isOgles2 );
	static void ResetPool();
	static void DestroyPool();

	static EmitterDesc* LinkEmitterDescPointer();
	static void FreeLinkEmitterDescPointer( EmitterDesc* ed );

	EmitterDesc* m_emitterDesc;
	int m_iTex;

	IFpsParticleEmitter* Emitter;
	array<IFpsParticleAffector*> AffectorList;

	float LastEmitTime;
	SColorf m_color;

	static EmitterDesc** m_poolEmitterDesc;
	static bool* m_poolEmitterUsed;
	static int m_poolMaxParticles;
	static int m_poolMaxEmitters;

	bool m_isEmittingEnabled;

	float m_posX; 
	float m_posY;
	float m_lastEmitPosX;
	float m_lastEmitPosY;
	int m_nbEmitWatting;
	virtual void SetPosition(float x, float y,bool bIsNew = false);

};

#endif

